/**
 * 作者: clz
 * 日期: 2025-05-04 16:45:28
 * 备注: 联盟折扣商店信息
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUnionDiscountShopInfo;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionDiscountShopInfoModel extends BaseModel implements Model {
	public static final String LISTKEY = "";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 联盟id
	protected int shopId; // 商品id (关联Union_discount_shop表id)
	protected int discountPrice; // 折扣价格
	protected int initPrice; // 初始价格
	protected long resetTime; // 重置时间

	public void reset() {
	}

	protected String getKey() {
		return "UnionDiscountShopInfo." + id;
	}

	protected String getListKey() {
		return null;
	}

	protected String getListItemKey() {
		return null;
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("union_discount_shop_info"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 联盟id
		obj.put("shopId", shopId); // 商品id (关联Union_discount_shop表id)
		obj.put("discountPrice", discountPrice); // 折扣价格
		obj.put("initPrice", initPrice); // 初始价格
		obj.put("resetTime", resetTime); // 重置时间
		return obj;
	}

	public PBUnionDiscountShopInfo.Builder takeInitBuilder() {
		PBUnionDiscountShopInfo.Builder sb = PBUnionDiscountShopInfo.newBuilder();
		if (shopId != 0) {
			sb.setShopId(shopId);
		}
		if (discountPrice != 0) {
			sb.setDiscountPrice(discountPrice);
		}
		if (initPrice != 0) {
			sb.setInitPrice(initPrice);
		}
		return sb;
	}

	public PBUnionDiscountShopInfo.Builder takeBuilder() {
		if (updateObj == null || updateObj.isEmpty()) {
			return takeInitBuilder();
		}
		PBUnionDiscountShopInfo.Builder sb = PBUnionDiscountShopInfo.newBuilder();
		if (isFieldUpdate("shopId")) {
			sb.setShopId(shopId);
		}
		if (isFieldUpdate("discountPrice")) {
			sb.setDiscountPrice(discountPrice);
		}
		if (isFieldUpdate("initPrice")) {
			sb.setInitPrice(initPrice);
		}
		return sb;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public int getShopId() {
		return shopId;
	}

	public void putShopId(int shopId) {
		if (this.shopId != shopId) {
			this.shopId = shopId;
			updateRedisHashField(getKey(), "shopId", this.shopId);
		}
	}

	public void addShopId(int value) {
		this.shopId += value;
		updateRedisHashField(getKey(), "shopId", this.shopId);
	}

	public int getDiscountPrice() {
		return discountPrice;
	}

	public void putDiscountPrice(int discountPrice) {
		if (this.discountPrice != discountPrice) {
			this.discountPrice = discountPrice;
			updateRedisHashField(getKey(), "discountPrice", this.discountPrice);
		}
	}

	public void addDiscountPrice(int value) {
		this.discountPrice += value;
		updateRedisHashField(getKey(), "discountPrice", this.discountPrice);
	}

	public int getInitPrice() {
		return initPrice;
	}

	public void putInitPrice(int initPrice) {
		if (this.initPrice != initPrice) {
			this.initPrice = initPrice;
			updateRedisHashField(getKey(), "initPrice", this.initPrice);
		}
	}

	public void addInitPrice(int value) {
		this.initPrice += value;
		updateRedisHashField(getKey(), "initPrice", this.initPrice);
	}

	public long getResetTime() {
		return resetTime;
	}

	public void putResetTime(long resetTime) {
		if (this.resetTime != resetTime) {
			this.resetTime = resetTime;
			updateRedisHashField(getKey(), "resetTime", this.resetTime);
		}
	}

	public void addResetTime(long value) {
		this.resetTime += value;
		updateRedisHashField(getKey(), "resetTime", this.resetTime);
	}

}